﻿//
// Created by francklinson on 2021/3/21.
//

#include "stack.h"

Stack::Stack()
{
    top = 0;
}

bool Stack::isEmpty() const
{
    return top == 0;
}

bool Stack::isFull() const
{
    return top == MAX;
}

bool Stack::push(const Item &item)
{
    if (top < MAX)
    {
        items[top++] = item;
        return true;
    } else
        return false;
}

bool Stack::pop(Item &item)
{
    if (top > 0)
    {
        item = items[--top];
        return true;
    } else
        return false;
}

void Stack::show()
{
    using std::cout;
    using std::endl;
    if (!isEmpty())
    {
        cout << "current stack:" << endl;
        for (int i = 0; i < top; i++)
        {
            cout << this->items[i] << endl;
        }
    } else
        cout << "stack is empty!" << endl;

}
